<%@page import="bean.MboardVO"%>
<%@page import="java.util.ArrayList"%>
<%@page import="bean.MboardDTO"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>list</title>
<link rel="stylesheet" href="../css/mboardlist.css">
<script src="../js/mboard.js"></script>
</head>
<body>
<jsp:useBean id="vo" class="bean.MboardVO" scope="page"></jsp:useBean>
<jsp:setProperty property="*" name="vo"/>
<div id = "list_title">
	<div class ="list_rno">No.</div>
	<div class ="list_category">분류</div>
	<div class ="list_subject">제목</div>
	<div class ="list_mid">작성자</div>
	<div class ="list_wdate">작성일</div>
	<div class ="list_vno">조회수</div>
</div>
<%
MboardDTO dto = new MboardDTO();
dto.setVo(vo);
ArrayList<MboardVO> ar = dto.select();
int p = dto.getListsize();
if(ar.size()<dto.getListsize()){
	p = ar.size();
}



for(int a = 0; a<p; a++){
	MboardVO v = ar.get(a);
	String s =v.getSubject();
	String [] t=v.getLev().split("-");
	switch(t.length){
	case 1 : break;
	case 2 : s="&nbsp;&nbsp;┖"+s; break;
	case 3 : s="&nbsp;&nbsp;&nbsp;&nbsp;┖"+s;break;
	}
	
	
	out.print("<a href='#' onclick='goView("+v.getRno()+")'>"+
	"<div id = 'list_item'>"+
	"<div class ='list_rno'>"+v.getRno()+"</div>"+
	"<div class ='list_category'>"+v.getCategory()+"</div>"+
	"<div class ='list_subject'>"+s+"</div>"+
	"<div class ='list_mid'>"+v.getMid()+"</div>"+
	"<div class ='list_wdate'>"+v.getWdate().substring(0,10)+"</div>"+
	"<div class ='list_vno'>"+v.getVno()+"</div>"+
	"</div></a><br>");
}

out.print("<font size='2'>Total "+dto.getTotpage()+" Page</font><br>");

if(vo.getNowpage()>1){
out.print("<a href='#' onclick='goPage(1)'> 처음으로 </a>");
out.print("<a href='#' onclick='goPage("+(dto.getNowpage()-1)+")'> ◀ </a>");
}



for(int a = dto.getStartpage();a<=dto.getEndpage();a++){
	if(dto.getNowpage()==a){
	out.print("["+a+"]");
	}else{
	out.print("<a href='#' onclick='goPage("+a+")'> "+ a +" </a>");
	}
}



if(vo.getNowpage()<dto.getTotpage()){
	out.print("<a href='#' onclick='goPage("+(dto.getNowpage()+1)+")'> ▶ </a>");
	out.print("<a href='#' onclick='goPage("+dto.getTotpage()+ ")'> 끝으로 </a>");

}

%>
<br><br>
<form name="searchfrm" method="post" action="board_main.jsp?inpage=../mboard/mboard_list.jsp">
<select size="1" name ="search">
<option value="*"<%if(vo.getSearch().equals("*")){out.print("selected='selected'");} %>>전체
<option value="mid" <%if(vo.getSearch().equals("mid")){out.print("selected='selected'");} %>>작성자
<option value="subject" <%if(vo.getSearch().equals("subject")){out.print("selected='selected'");} %>>제목
<option value="content" <%if(vo.getSearch().equals("content")){out.print("selected='selected'");} %>>내용
<option value="wdate" <%if(vo.getSearch().equals("wdate")){out.print("selected='selected'");} %>>작성일
<option value="category" <%if(vo.getSearch().equals("category")){out.print("selected='selected'");} %>>분류
</select>
<input type="text" name="find" value="<%=vo.getFind()%>">
<input type="button" id="findgo" value="검 색">
<input type="button" id="mainlist" value="목록으로">
</form>


<%
if(session.getAttribute("sessionMid")!=null){
%>
<br>
<input type="button" id="btninput" value="글쓰기">
<%} %>
<form name="listfrm" method="post">
	<input type="hidden" name="rno">
	<input type="hidden" name="search" value="<%=vo.getSearch()%>">
	<input type="hidden" name="find" value="<%=vo.getFind()%>">
	<input type="hidden" name="nowpage" value="<%=vo.getNowpage()%>">
</form>

<script>listinit();</script>
</body>
</html>